import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

/**
 * @author: Themberfue
 * @date: 2025/4/5 10:36
 * @description:
 */
public class RedisList {
    public static void main(String[] args) {
        try (JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
             Jedis jedis = jedisPool.getResource()) {
            blpopAndLlen(jedis);
        }
    }

    private static void blpopAndLlen(Jedis jedis) {
        jedis.flushAll();

        List<String> blpopRes = jedis.blpop(100, "k1");
        System.out.println("key:" + blpopRes.get(0));
        System.out.println("val:" + blpopRes.get(1));

        long len = jedis.llen("k1");
        System.out.println(len);
    }

    private static void lpopAndRpop(Jedis jedis) {
        jedis.flushAll();

        jedis.rpush("k1", "111", "222", "333");
        String res = jedis.lpop("k1");
        System.out.println(res);

        res = jedis.lpop("k1");
        System.out.println(res);

        res = jedis.lpop("k1");
        System.out.println(res);

        res = jedis.lpop("k1");
        System.out.println(res);

        jedis.rpush("k1", "111", "222", "333");
        res = jedis.rpop("k1");
        System.out.println(res);

        res = jedis.rpop("k1");
        System.out.println(res);

        res = jedis.rpop("k1");
        System.out.println(res);

        res = jedis.rpop("k1");
        System.out.println(res);
    }

    private static void rpush(Jedis jedis) {
        jedis.flushAll();

        jedis.rpush("k1", "111", "222", "333");

        List<String> lrangeRes = jedis.lrange("k1", 0, -1);
        System.out.println(lrangeRes);
    }

    private static void lpushAndLrange(Jedis jedis) {
        jedis.flushAll();

        jedis.lpush("k1", "111", "222", "333");

        List<String> lrangeRes = jedis.lrange("k1", 0, -1);
        System.out.println(lrangeRes);
    }


}
